package chances.wechat.api;

import org.springframework.beans.factory.annotation.Autowired;

import chances.wechat.log.WechatLogger;

public class TokenWeixinResovlerImpl implements TokenResovler {

	@Autowired
	WechatLogger wxLogger;

	/*
	 * (non-Javadoc)
	 * 
	 * @see chances.weixin.api.TokenResovler#getToken(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public String getToken(String appId, String secret) {
//		String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret="
//				+ secret;
//		String resultJson = HttpUtils.get(url, null);
//		Map<String, Object> response = JSONUtils.toMap(resultJson);
//		String accessToken = (String) response.get("access_token");
//		if (null == accessToken) {
//			throw new WechatException("微信公众号token获取出错，错误信息:" + response.get("errcode") + "," + response.get("errmsg"));
//		}
//		wxLogger.logToken(appId, accessToken, resultJson);
//		return accessToken;
	    return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see chances.weixin.api.TokenResovler#getJSToken(java.lang.String)
	 */
	@Override
	public String getJSToken(String accessToken) {
//		String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
//		String resultJson = HttpUtils.get(url, null);
//		Map<String, Object> response = JSONUtils.toMap(resultJson);
//		String ticket = (String) response.get("ticket");
//		if (StringUtils.isBlank(ticket)) {
//			throw new WechatException(
//					"微信公众号jsToken获取出错，错误信息:" + response.get("errcode") + "," + response.get("errmsg"));
//		}
//		wxLogger.logJsapiTicket(accessToken, ticket, resultJson);
//		return ticket;
	    return null;
	}

	public WechatLogger getWxLogger() {
		return wxLogger;
	}

	public void setWxLogger(WechatLogger wxLogger) {
		this.wxLogger = wxLogger;
	}
}
